package com.mocha.common.kits;

import com.mocha.common.kits.RandomKits;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

/**
 * @author: songkui
 * @date: 2023/3/20 18:18
 */
public class SevenDragonBalls {

    public static void main(String[] args) {
        for (int i=0; i<5; i++){
            sevenDragonBalls(true);
            System.out.println();
        }
        //for (int j=0; j<10; j++){
        //    if (j%2 == 0){
        //        System.out.println("--------"+j);
        //        continue;
        //    }
        //    System.out.println("+++++++++++++" +j);
        //
        //}
    }

    private static void sevenDragonBalls(boolean isSsq){

        int redMax = isSsq ? 33 : 35;
        List<Integer> balls = new ArrayList<>(redMax);
        for (int i=1; i<=redMax; i++){
            balls.add(i);
        }
        Collections.shuffle(balls);

        int redLength = isSsq ? 6 : 5;
        for (int i=0; i<redLength; i++){
            System.out.print(rotateBall(balls) +"  ");
        }

        System.out.print("  :  ");
        int blueMax = isSsq ? 16 : 12;
        List<Integer> blueBalls = new ArrayList<>(blueMax);
        for (int i=1; i<=blueMax; i++){
            blueBalls.add(i);
        }
        Collections.shuffle(blueBalls);

        int blueLength = isSsq ? 1 : 2;
        for (int i=0; i<blueLength; i++){
            System.out.print(rotateBallBlue(blueBalls) +" ");
        }

    }

    private static String  rotateBall(List<Integer> balls){
        Iterator<Integer> iterator = balls.iterator();
        while (iterator.hasNext()){
            Integer ball = iterator.next();
            if (collider(ball)){
                iterator.remove();
                return fillString(ball, 2);
            }
        }
        return rotateBall(balls);
    }

    private static String  rotateBallBlue(List<Integer> balls){
        Iterator<Integer> iterator = balls.iterator();
        while (iterator.hasNext()){
            Integer ball = iterator.next();
            if (colliderBlue(ball)){
                iterator.remove();
                return fillString(ball, 2);
            }
        }
        return rotateBallBlue(balls);
    }

    private static boolean collider(Integer target){
        int times = RandomKits.randomInt(1, 2);
        for (int i=0; i<times; i++){
            if (target == RandomKits.randomInt(36)){
                return true;
            }
        }
        return false;
    }

    private static boolean colliderBlue(Integer target){
        int times = RandomKits.randomInt(1, 2);
        for (int i=0; i<times; i++){
            if (target == RandomKits.randomInt(13)){
                return true;
            }
        }
        return false;
    }


    /**
     * 0：表示前面补0
     * digit：表示保留数字位数
     * d：表示参数为正数类型
     */
    public static String fillString(int num , int digit) {
        return String.format("%0"+digit+"d", num);
    }

}
